package com.projectplace.api;

/*
 * Copyright (c) 2011 Projectplace International AB
 * Permission is hereby granted, free of charge, to any person 
 * obtaining a copy of this software and associated documentation 
 * files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, 
 * publish, distribute, sublicense, and/or sell copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, 
 * subject to the following conditions:The above copyright notice and this 
 * permission notice shall be included in all copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


import org.apache.http.HttpResponse;
import com.projectplace.api.Callback.Callback;
import com.projectplace.api.CallbackWrapper.CallbackWrapper;
import android.os.Handler;
import android.util.Log;
import android.widget.ImageView;

/**
 * 
 * @author johanma
 *
 */

public class UserApi implements Api{

	private UserApi(){super();}	
	
	public static void getProfile(PPClient client,final Handler handler, String userID,final Callback.ResponseListenerGetProfile response){
		String fetchUri =  PROJECTPLACE_BASIC_API +userID +"/profile.json";
		PPClient.sendRequest(fetchUri, new getInfoHandler(){
			public void onFinish(HttpResponse user, Error err){
				CallbackWrapper.GetProfile tempWrap = new CallbackWrapper.GetProfile(response);
				tempWrap.setResponse(user,err);
				handler.post(tempWrap);
			}
		});
	}

	public static void getCoWorkers(PPClient client,final Handler handler,final Callback.ResponseListenerGetCoWorkers response){
		String fetchUri =  PROJECTPLACE_USER_COWORKERS;
		PPClient.sendRequest(fetchUri, new getInfoHandler(){
			public void onFinish(HttpResponse user, Error err){
				CallbackWrapper.GetCoWorkers tempWrap = new CallbackWrapper.GetCoWorkers(response);
				tempWrap.setResponse(user,err);
				handler.post(tempWrap);
			}
		});
	}
	
	public static void getUserProjects(PPClient client,final Handler handler,final Callback.ResponseListenerUserProjects response){
		String fetchUri =  PROJECTPLACE_USER_PROJECTS;
		PPClient.sendRequest(fetchUri, new getInfoHandler(){
			public void onFinish(HttpResponse user, Error err){
				Log.d("UserApi", "test");
				CallbackWrapper.UserProjects tempWrap = new CallbackWrapper.UserProjects(response);
				tempWrap.setResponse(user,err);
				handler.post(tempWrap);
			}
		});
	}
	
	public static void getAvatar(PPClient client,String userID,ImageView view){
		client.sendAvatarRequest(PROJECTPLACE_USER_AVARTAR+userID,userID, view);
	}
	
	public static void getUserAssignments(PPClient client,final Handler handler,final Callback.ResponseListenerUserAssignments response){
		String fetchUri =  PROJECTPLACE_USER_Assignments;
		PPClient.sendRequest(fetchUri, new getInfoHandler(){
			public void onFinish(HttpResponse user, Error err){
				Log.d("UserApi", "test");
				CallbackWrapper.UserAssignments tempWrap = new CallbackWrapper.UserAssignments(response);
				tempWrap.setResponse(user,err);
				handler.post(tempWrap);
			}
		});
	}
	
	
}
